// manager/pages/customerdistribution/index.js
import config from '../../../utils/config';
import { getSystemInfo } from '../../../utils/getSystemInfo';
import { request } from '../../../utils/request';
import util from '../../../common/util';
import WxValidate from '../../../common/WxValidate';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        baseUrl: config.baseUrl,
        userInfo: {},
        type: "", // 1自己，2全部
        params: {
            search: "",
            perType: "", // 个人客户类型
            areaName: "", // 网格名称       
            industry: "",
            locationName: "",
            agrType: "", // 农业主体类型
            agrLicenseName: "", // 营业执照名称
        },
        // 客户分布
        latitude: "",
        longitude: "",
        markers: [
            // {
            //     id: 1,
            //     latitude: 35.426365,
            //     longitude: 116.705696,
            //     iconPath: '/static/images/bb.png',
            //     width: 20,
            //     height: 20,
            //     title: "共和国的更换更换",
            //     customCallout: {
            //         anchorY: 10,
            //         anchorX: 0,
            //         display: 'ALWAYS',
            //     },
            // },
        ],
        circles: [],
        mapRadius: 0,
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {
        this.getDictionaryInfo();
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        this.getUserInfo();
    },
    // 获取当前登录者的用户信息
    getUserInfo(e) {        
        request({
            url: "/user/getUserInfo",
            reqRSAENCRY: true, // 参数是否加密
            resRSADECRY: true, // 返回值是否解密
            data: {}
        }).then(res => {
            if(res.code == 0){
                let { userInfo } = this.data;
                let postCodeArr = userInfo.extendPostCode?userInfo.extendPostCode.split(","):[];
                this.setData({
                    userInfo: res.data.userInfo,
                    type: postCodeArr.indexOf("wg") != -1 ? 2 : 1
                })
                this.getData();
            }
        }).catch(error => {
            // console.log(error)
        })
    },
    /**
     * 获取字典
     */
    getDictionaryInfo() {
        request({
            url: "/commonApi/getDictionaryInfo",
            method: "GET",
            data: {
				dictType: "ecard_cust_type"
			}
        }).then(res => {
            if(res.code == 0){
                let subTab = [];
                let typeList = [
                    {
                        dictLabel: "全部",
                        dictValue: ""
                    }
                ];
                // 是否显示个人
                if(this.data.isPerson){
                    subTab = res.data;
                }else{
                    res.data.forEach(item => {
                        if(item.dictValue != 1){
                            subTab.push(item)
                        }
                    })
                }
                this.setData({
                    subTab,
                    typeList: typeList.concat(subTab)
                })
            }
            return request({
                url: "/commonApi/getDictionaryInfo",
                method: "GET",
                data: {
                    dictType: "ecard_person_type"
                }
            })
        }).then(res => {
            if(res.code == 0){
                let personTypeList = [
                    {
                        dictLabel: "全部",
                        dictValue: ""
                    }
                ];
                this.setData({
                    personTypeList: personTypeList.concat(res.data)
                })
            }
            return request({
                url: "/commonApi/getDictionaryInfo",
                method: "GET",
                data: {
                    dictType: "ecard_merchant_industry"
                }
            })
        }).then(res => {
            if(res.code == 0){
                let merchantIndustryList = [];
                merchantIndustryList.push({
                    dictLabel: "全部",
                    dictValue: ""
                })
                this.setData({
                    merchantIndustryList: merchantIndustryList.concat(res.data)
                })
            }
            return request({
                url: "/commonApi/getDictionaryInfo",
                method: "GET",
                data: {
                    dictType: "ecard_enterprise_industry"
                }
            })
        }).then(res => {
            if(res.code == 0){
                let enterpriseIndustryList = [];
                enterpriseIndustryList.push({
                    dictLabel: "全部",
                    dictValue: ""
                })
                this.setData({
                    enterpriseIndustryList: enterpriseIndustryList.concat(res.data)
                })
            }
            return request({
                url: "/commonApi/getDictionaryInfo",
                method: "GET",
                data: {
                    dictType: "ecard_agriculture_type"
                }
            })
        }).then(res => {
            if(res.code == 0){
                let agricultureTypeList = [];
                agricultureTypeList.push({
                    dictLabel: "全部",
                    dictValue: ""
                })
                this.setData({
                    agricultureTypeList: agricultureTypeList.concat(res.data)
                })
            }
        }).catch(error => {
            // console.log(error)
        })

        
    },
    /**
     * 获取地图范围半径
     */
    getSysConfigInfo(fn) {
        request({
            url: "/commonApi/getSysConfigInfo",
            method: "GET",
            data: {
                configKey: "ecard_merchant_show_distance"
            }
        }).then(res => {
            if(res.code == 0){
                this.setData({
                    mapRadius: Number(res.data.configValue)
                })
                fn&&fn();
            }
        }).catch(error => {
            // console.log(error)
        })
    },

    searchBtn(e){
        this.getData();
    },
    bindTypeChange(e){
        this.setData({
            typeIndex: e.detail.value,
            industryIndex: -1,
            'params.industry': ""
        })
    },
    bindPersonTypeChange(e){
        this.setData({
            personTypeIndex: e.detail.value,
            'params.perType': this.data.personTypeList[e.detail.value].dictValue
        })
    },
    bindMerchantIndustryChange(e){
        this.setData({
            industryIndex: e.detail.value,
            'params.industry': this.data.merchantIndustryList[e.detail.value].dictValue
        })
    },
    bindEnterpriseIndustryChange(e){
        this.setData({
            industryIndex: e.detail.value,
            'params.industry': this.data.enterpriseIndustryList[e.detail.value].dictValue
        })
    },
    bindAgricultureTypeChange(e){
        this.setData({
            agricultureTypeIndex: e.detail.value,
            'params.agrType': this.data.agricultureTypeList[e.detail.value].dictValue
        })
    },
    /**
     * 获取数据
     */
    getData() {
        this.getSysConfigInfo(() => {
            // 地图
            if(this.data.latitude){
                this.getMapList()
            }else{
                this.getLatLng();
            }
        });
    },

    /**
     * 获取地图数据
     */
    async getMapList(){
        let { isPerson, typeIndex } = this.data;
        let markers = [];
        markers.push({
            id: 0,
            latitude: this.data.latitude,
            longitude: this.data.longitude,
            iconPath: '../../resources/images/dw.png',
            width: 25,
            height: 25,
            anchor: {
                x: .5, 
                y: .5, 
            }
        })
        this.setData({
            markers
        })
        if(isPerson){
            // 全部
            if(typeIndex < 1){
                this.getPersonCoordinateList();
                this.getPersonAreaCoordinateList();
                this.getMerchantCoordinateList();
                this.getEnterpriseCoordinateList();
                this.getLocationCoordinateList();
                this.getAgricultureCoordinateList();
            }
            // 个人
            if(typeIndex == 1){
                this.getPersonCoordinateList();
                this.getPersonAreaCoordinateList();
            }
            // 商户
            if(typeIndex == 2){
                this.getMerchantCoordinateList();
            }
            // 企业
            if(typeIndex == 3){
                this.getEnterpriseCoordinateList();
                this.getLocationCoordinateList();
            }
            // 新型农业主体
            if(typeIndex == 4){
                this.getAgricultureCoordinateList();
            }
        }else{
            // 全部
            if(typeIndex < 1){
                this.getMerchantCoordinateList();
                this.getEnterpriseCoordinateList();
                this.getLocationCoordinateList();
                this.getAgricultureCoordinateList();
            }
            // 商户
            if(typeIndex == 1){
                this.getMerchantCoordinateList();
            }
            // 企业
            if(typeIndex == 2){
                this.getEnterpriseCoordinateList();
                this.getLocationCoordinateList();
            }
            // 新型农业主体
            if(typeIndex == 3){
                this.getAgricultureCoordinateList();
            }
        }
    },

    /**
     * 获取地图个人列表
     */
    getPersonCoordinateList() {
        request({
            url: `/personMarketing/getPersonCoordinateList`,
            reqRSAENCRY: true, // 参数是否加密
            resRSADECRY: true, // 返回值是否解密
            data: {
                type: this.data.type,
                perType: this.data.params.perType,
                coordinate: `${this.data.latitude},${this.data.longitude}`
            }
        }).then(res => {
            if(res.code == 0){
                console.log(res)
                // this.setData({
                //     mapList: res.data
                // })
                let markers = [];
                res.data.forEach((item,index) => {
                    // 1 别人    2  自己
                    if(item.oneself == 2){
                        markers.push({
                            id: (this.data.markers.length + index),
                            latitude: item.manageCoordinate.split(",")[0],
                            longitude: item.manageCoordinate.split(",")[1],
                            iconPath: '/manager/resources/images/map_e_zflag.png',
                            width: 25,
                            height: 25,
                            merchantId: item.id,
                            title: item.perCustName.length>6?item.perCustName.substr(0,6):item.perCustName,
                            // headPic: item.headPic,
                            type: 1,
                            oneself: item.oneself,
                            customCallout: {
                                anchorY: 0,
                                anchorX: 0,
                                display: 'ALWAYS', // BYCLICK
                            },
                        })
                    }else{
                        markers.push({
                            id: (this.data.markers.length + index),
                            latitude: item.manageCoordinate.split(",")[0],
                            longitude: item.manageCoordinate.split(",")[1],
                            iconPath: '/manager/resources/images/map_e_oflag.png',
                            width: 25,
                            height: 25,
                            merchantId: item.id,
                            title: item.perCustName.length>6?item.perCustName.substr(0,6):item.perCustName,
                            // headPic: item.headPic,
                            type: 1,
                            oneself: item.oneself,
                            customCallout: {
                                anchorY: 0,
                                anchorX: 0,
                                display: 'ALWAYS', // BYCLICK
                            },
                        })
                    }
                    
                })
                this.setData({
                    markers: this.data.markers.concat(markers)
                })
            }
        }).catch(error => {
            // console.log(error)
        })
    },
    /**
     * 获取地图网格列表
     */
    getPersonAreaCoordinateList() {
        request({
            url: `/personMarketing/getPersonAreaCoordinateList`,
            reqRSAENCRY: true, // 参数是否加密
            resRSADECRY: true, // 返回值是否解密
            data: {
                type: this.data.type,
                // industry: this.data.params.industry,
                coordinate: `${this.data.latitude},${this.data.longitude}`
            }
        }).then(res => {
            if(res.code == 0){
                console.log(res)
                // this.setData({
                //     mapList: res.data
                // })
                let markers = [];
                res.data.forEach((item,index) => {
                    // 1 别人    2  自己
                    if(item.oneself == 2){
                        markers.push({
                            id: (this.data.markers.length + index),
                            latitude: item.areaAbbreviation.split(",")[0],
                            longitude: item.areaAbbreviation.split(",")[1],
                            iconPath: '/manager/resources/images/map_b_zflag.png',
                            width: 25,
                            height: 25,
                            merchantId: item.id,
                            title: item.areaAbbreviation.length>6?item.areaAbbreviation.substr(0,6):item.areaAbbreviation,
                            // headPic: item.headPic,
                            type: 'wangge',
                            oneself: item.oneself,
                            customCallout: {
                                anchorY: 0,
                                anchorX: 0,
                                display: 'ALWAYS', // BYCLICK
                            },
                        })
                    }else{
                        markers.push({
                            id: (this.data.markers.length + index),
                            latitude: item.areaAbbreviation.split(",")[0],
                            longitude: item.areaAbbreviation.split(",")[1],
                            iconPath: '/manager/resources/images/map_b_oflag.png',
                            width: 25,
                            height: 25,
                            merchantId: item.id,
                            title: item.areaAbbreviation.length>6?item.areaAbbreviation.substr(0,6):item.areaAbbreviation,
                            // headPic: item.headPic,
                            type: 'wangge',
                            oneself: item.oneself,
                            customCallout: {
                                anchorY: 0,
                                anchorX: 0,
                                display: 'ALWAYS', // BYCLICK
                            },
                        })
                    }
                    
                })
                this.setData({
                    markers: this.data.markers.concat(markers)
                })
            }
        }).catch(error => {
            // console.log(error)
        })
    },

    /**
     * 获取地图商户列表
     */
    getMerchantCoordinateList() {
        request({
            url: `/merchantMarketing/getMerchantCoordinateList`,
            reqRSAENCRY: true, // 参数是否加密
            resRSADECRY: true, // 返回值是否解密
            data: {
                type: this.data.type,
                industry: this.data.params.industry,
                coordinate: `${this.data.latitude},${this.data.longitude}`
            }
        }).then(res => {
            if(res.code == 0){
                console.log(res)
                // this.setData({
                //     mapList: res.data
                // })
                let markers = [];
                res.data.forEach((item,index) => {
                    // 1 别人    2  自己
                    if(item.oneself == 2){
                        markers.push({
                            id: (this.data.markers.length + index),
                            latitude: item.coordinate.split(",")[0],
                            longitude: item.coordinate.split(",")[1],
                            iconPath: '/manager/resources/images/map_m_zflag.png',
                            width: 25,
                            height: 25,
                            merchantId: item.id,
                            title: item.handName.length>6?item.handName.substr(0,6):item.handName,
                            // headPic: item.headPic,
                            type: 2,
                            oneself: item.oneself,
                            customCallout: {
                                anchorY: 0,
                                anchorX: 0,
                                display: 'ALWAYS', // BYCLICK
                            },
                        })
                    }else{
                        markers.push({
                            id: (this.data.markers.length + index),
                            latitude: item.coordinate.split(",")[0],
                            longitude: item.coordinate.split(",")[1],
                            iconPath: '/manager/resources/images/map_m_oflag.png',
                            width: 25,
                            height: 25,
                            merchantId: item.id,
                            title: item.handName.length>6?item.handName.substr(0,6):item.handName,
                            // headPic: item.headPic,
                            type: 2,
                            oneself: item.oneself,
                            customCallout: {
                                anchorY: 0,
                                anchorX: 0,
                                display: 'ALWAYS', // BYCLICK
                            },
                        })
                    }
                    
                })
                this.setData({
                    markers: this.data.markers.concat(markers)
                })
            }
        }).catch(error => {
            // console.log(error)
        })
    },

    /**
     * 获取地图企业列表
     */
    getEnterpriseCoordinateList() {
        request({
            url: `/enterpriseMarketing/getEnterpriseCoordinateList`,
            reqRSAENCRY: true, // 参数是否加密
            resRSADECRY: true, // 返回值是否解密
            data: {
                type: this.data.type,
                industry: this.data.params.industry,
                coordinate: `${this.data.latitude},${this.data.longitude}`
            }
        }).then(res => {
            if(res.code == 0){
                console.log(res)
                // this.setData({
                //     mapList: res.data
                // })
                let markers = [];
                res.data.forEach((item,index) => {
                    // 1 别人    2  自己
                    if(item.oneself == 2){
                        markers.push({
                            id: (this.data.markers.length + index),
                            latitude: item.entCoordinate.split(",")[0],
                            longitude: item.entCoordinate.split(",")[1],
                            iconPath: '/manager/resources/images/map_e_zflag.png',
                            width: 25,
                            height: 25,
                            merchantId: item.id,
                            title: item.entAlias?item.entAlias.length>6?item.entAlias.substr(0,6):item.entAlias:item.entName.length>6?item.entName.substr(0,6):item.entName,
                            // headPic: item.headPic,
                            type: 3,
                            oneself: item.oneself,
                            customCallout: {
                                anchorY: 0,
                                anchorX: 0,
                                display: 'ALWAYS', // BYCLICK
                            },
                        })
                    }else{
                        markers.push({
                            id: (this.data.markers.length + index),
                            latitude: item.entCoordinate.split(",")[0],
                            longitude: item.entCoordinate.split(",")[1],
                            iconPath: '/manager/resources/images/map_e_oflag.png',
                            width: 25,
                            height: 25,
                            merchantId: item.id,
                            title: item.entAlias?item.entAlias.length>6?item.entAlias.substr(0,6):item.entAlias:item.entName.length>6?item.entName.substr(0,6):item.entName,
                            // headPic: item.headPic,
                            type: 3,
                            oneself: item.oneself,
                            customCallout: {
                                anchorY: 0,
                                anchorX: 0,
                                display: 'ALWAYS', // BYCLICK
                            },
                        })
                    }
                    
                })
                this.setData({
                    markers: this.data.markers.concat(markers)
                })
            }
        }).catch(error => {
            // console.log(error)
        })
    },
    /**
     * 获取地图楼宇列表
     */
    getLocationCoordinateList() {
        request({
            url: `/enterpriseMarketing/getLocationCoordinateList`,
            reqRSAENCRY: true, // 参数是否加密
            resRSADECRY: true, // 返回值是否解密
            data: {
                type: this.data.type,
                industry: this.data.params.industry,
                coordinate: `${this.data.latitude},${this.data.longitude}`
            }
        }).then(res => {
            if(res.code == 0){
                console.log(res)
                // this.setData({
                //     mapList: res.data
                // })
                let markers = [];
                res.data.forEach((item,index) => {
                    // 1 别人    2  自己
                    if(item.oneself == 2){
                        markers.push({
                            id: (this.data.markers.length + index),
                            latitude: item.locationCoordinate.split(",")[0],
                            longitude: item.locationCoordinate.split(",")[1],
                            iconPath: '/manager/resources/images/map_b_zflag.png',
                            width: 25,
                            height: 25,
                            merchantId: item.id,
                            title: item.locationAbbreviation.length>6?item.locationAbbreviation.substr(0,6):item.locationAbbreviation,
                            // headPic: item.headPic,
                            type: 'louyu',
                            oneself: item.oneself,
                            customCallout: {
                                anchorY: 0,
                                anchorX: 0,
                                display: 'ALWAYS', // BYCLICK
                            },
                        })
                    }else{
                        markers.push({
                            id: (this.data.markers.length + index),
                            latitude: item.locationCoordinate.split(",")[0],
                            longitude: item.locationCoordinate.split(",")[1],
                            iconPath: '/manager/resources/images/map_b_oflag.png',
                            width: 25,
                            height: 25,
                            merchantId: item.id,
                            title: item.locationAbbreviation.length>6?item.locationAbbreviation.substr(0,6):item.locationAbbreviation,
                            // headPic: item.headPic,
                            type: 'louyu',
                            oneself: item.oneself,
                            customCallout: {
                                anchorY: 0,
                                anchorX: 0,
                                display: 'ALWAYS', // BYCLICK
                            },
                        })
                    }
                    
                })
                this.setData({
                    markers: this.data.markers.concat(markers)
                })
            }
        }).catch(error => {
            // console.log(error)
        })
    },

    /**
     * 获取地图新型农业主体列表
     */
    getAgricultureCoordinateList() {
        request({
            url: `/agricultureMarketing/getAgricultureCoordinateList`,
            reqRSAENCRY: true, // 参数是否加密
            resRSADECRY: true, // 返回值是否解密
            data: {
                type: this.data.type,
                industry: this.data.params.industry,
                coordinate: `${this.data.latitude},${this.data.longitude}`
            }
        }).then(res => {
            if(res.code == 0){
                console.log(res)
                // this.setData({
                //     mapList: res.data
                // })
                let markers = [];
                res.data.forEach((item,index) => {
                    // 1 别人    2  自己
                    if(item.oneself == 2){
                        markers.push({
                            id: (this.data.markers.length + index),
                            latitude: item.agrCoordinate.split(",")[0],
                            longitude: item.agrCoordinate.split(",")[1],
                            iconPath: '/manager/resources/images/map_a_zflag.png',
                            width: 25,
                            height: 25,
                            merchantId: item.id,
                            title: item.agrCustName.length>6?item.agrCustName.substr(0,6):item.agrCustName,
                            // headPic: item.headPic,
                            type: 4,
                            oneself: item.oneself,
                            customCallout: {
                                anchorY: 0,
                                anchorX: 0,
                                display: 'ALWAYS', // BYCLICK
                            },
                        })
                    }else{
                        markers.push({
                            id: (this.data.markers.length + index),
                            latitude: item.agrCoordinate.split(",")[0],
                            longitude: item.agrCoordinate.split(",")[1],
                            iconPath: '/manager/resources/images/map_a_oflag.png',
                            width: 25,
                            height: 25,
                            merchantId: item.id,
                            title: item.agrCustName.length>6?item.agrCustName.substr(0,6):item.agrCustName,
                            // headPic: item.headPic,
                            type: 4,
                            oneself: item.oneself,
                            customCallout: {
                                anchorY: 0,
                                anchorX: 0,
                                display: 'ALWAYS', // BYCLICK
                            },
                        })
                    }
                    
                })
                this.setData({
                    markers: this.data.markers.concat(markers)
                })
            }
        }).catch(error => {
            // console.log(error)
        })
    },

    // 查看定位
    viewLocation(e){
        let that = this;
        wx.chooseLocation({
            latitude: this.data.latitude,
            longitude: this.data.longitude,
            scale: 18,
            success(res){
                console.log(res)
                let latitude = res.latitude;
                let longitude = res.longitude;
                let circles = [];
                circles.push({
                    latitude: latitude,
                    longitude: longitude,
                    radius: that.data.mapRadius,
                    fillColor: "#148dff20",
                    color: "#148dff",
                    strokeWidth: 1
                })
                that.setData({
                    latitude,
                    longitude,
                    circles
                })
                that.getMapList()
            }
        })
    },
    // 点击地图选点
    onTapMap(e){
        let { latitude, longitude } = e.detail;
        let circles = [];
        circles.push({
            latitude: latitude,
            longitude: longitude,
            radius: this.data.mapRadius,
            fillColor: "#148dff20",
            color: "#148dff",
            strokeWidth: 1
        })
        this.setData({
            latitude: latitude,
            longitude: longitude,
            circles
        })
        this.getMapList();
    },
    // poi点击回调
	onTapPoi (e) {
		let { latitude, longitude } = e.detail;
        let circles = [];
        circles.push({
            latitude: latitude,
            longitude: longitude,
            radius: this.data.mapRadius,
            fillColor: "#148dff20",
            color: "#148dff",
            strokeWidth: 1
        })
        this.setData({
            latitude: latitude,
            longitude: longitude,
            circles
        })
        this.getMapList();
	},
    // 点击地图图标
    markertap(e){
        console.log(e.detail)
        let { markerId } = e.detail;
        let { markers } = this.data;
        // var item = markers.find(item => item.id == markerId);
        let item = markers[markerId];
        console.log(item)
        // 1 别人    2 自己
        if(item&&item.oneself==2){
            if(item.type == 'wangge'){
                wx.navigateTo({
                    url: `/manager/pages/areadesc/index?id=${item.merchantId}&name=${item.title}&merchantType=1`,
                })
            }else if(item.type == 'louyu'){
                wx.navigateTo({
                    url: `/manager/pages/buildingdesc/index?id=${item.merchantId}&name=${item.title}&merchantType=3`,
                })
            }else{
                wx.navigateTo({
                    url: `/manager/pages/visit/index?merchantId=${item.merchantId}&merchantType=${item.type}`,
                })
            }
        }
    },
    // 点击汽包
    callouttap(e){
        console.log(e.detail)
        let { markerId } = e.detail;
        let { markers } = this.data;
        // var item = markers.find(item => item.id == markerId);
        let item = markers[markerId];
        console.log(item)
        // 1 别人    2  自己
        if(item&&item.oneself==2){
            if(item.type == 'wangge'){
                wx.navigateTo({
                    url: `/manager/pages/areadesc/index?id=${item.merchantId}&name=${item.title}&merchantType=1`,
                })
            }else if(item.type == 'louyu'){
                wx.navigateTo({
                    url: `/manager/pages/buildingdesc/index?id=${item.merchantId}&name=${item.title}&merchantType=3`,
                })
            }else{
                wx.navigateTo({
                    url: `/manager/pages/visit/index?merchantId=${item.merchantId}&merchantType=${item.type}`,
                })
            }
        }
    },
    // 获取经纬度
    getLatLng(){
        let that = this;
        wx.getSetting({
            success: (res) => {
                if (res.authSetting['scope.userLocation'] == false) {//非初始化进入该页面,且未授权
                    wx.showModal({
                        title: '是否授权当前位置',
                        content: '需要获取您的地理位置，请确认授权',
                        success: function (res) {
                            // if (res.cancel) {
                            //     that.getAccountManagerList()
                            // } else 
                            if (res.confirm) {
                                wx.openSetting({
                                    success: function (data) {
                                        // console.log(data);
                                        if (data.authSetting["scope.userLocation"] == true) {
                                            that.getLocation();
                                        }else{
                                            that.getMapList()
                                        }
                                    }
                                })
                            }
                        }
                    })
                } else {//初始化进入
                    // console.log("KKKKK") 
                    if(that.data.latitude){
                        that.getMapList()
                    }else{
                        that.getLocation();
                    }
                }
            }
        })
    },
    getLocation(){
        const that = this;
        wx.getLocation({
            type: 'gcj02',
            altitude: true,
            isHighAccuracy: true,
            success (res) {
                let circles = [];
                circles.push({
                    latitude: res.latitude,
                    longitude: res.longitude,
                    radius: that.data.mapRadius,
                    fillColor: "#148dff20",
                    color: "#148dff",
                    strokeWidth: 1
                })
                that.setData({
                    latitude: res.latitude,
                    longitude: res.longitude,
                    circles
                })
                that.getMapList();
            },
            complete: function(res) {
                if(res.errMsg == "getLocation:fail auth deny"){
                    // wx.showToast({
                    //     title: '获取定位失败',
                    //     icon: 'none',
                    //     duration: 2000
                    // });
                }
            }
        })
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },
})